window.addEventListener('load',function () {
    var ps = document.getElementById('provence');
    var cs = document.getElementById('city');
    var ss = document.getElementById('street');
    var ds = document.getElementById("d-s")
    var Val = '<option value="-1">请选择</option>';
 
         
         $(function(){    
            for(var i=0;i<json.citylist.length;i++){
                //从json数组中获取所有省、直辖市，并且添加到下拉框中
                ps.innerHTML += "<option value = "+ i + ">" + json.citylist[i].p + "</option>";
            }
             });
   
    //省下拉框的改变事件
    ps.onchange = function(){
        Val = '<option value="-1">请选择</option>';
        //这一段if-else代码是为了判断是否为直辖市，如果为直辖市，则最后一个县区的下拉框隐藏
        if(json.citylist[ps.value].c[0].a == undefined){
            ds.style.display='none';
        }else{
            ds.style.display='inline-block';
        }
        if(ps.value == -1){
            cs.innerHTML= Val;
        }
        for(var j=0;j<json.citylist[ps.value].c.length;j++) {
            Val += "<option value = " + j + ">" + json.citylist[ps.value].c[j].n + "</option>";
            cs.innerHTML = Val;
        }
        ss.innerHTML = '<option value="-1">请选择</option>';
    }
//城市下拉框的改变事件
    cs.onchange = function(){
    //当选中的省不是直辖市时，才会运行此函数
        if(ss.style.display == "inline-block"){
            Val = '<option value="-1">请选择</option>';
            if(ps.value == -1 || cs.value== -1){
                ss.innerHTML= Val;
            }
            
           
        }else{
            Val = "";
 
             for(var j=0;j<json.citylist[ps.value].c[cs.value].a.length;j++){
                Val += "<option value = " + j + ">" + json.citylist[ps.value].c[cs.value].a[j].s + "</option>";
                ss.innerHTML = Val;
            }
        }
    }

    var zhifubao =  document.querySelector('.zhifubao');
    var weixin = document.querySelector('.weixin');
    var yinlian = document.querySelector('.yinlian');
    var lis = [zhifubao,weixin,yinlian];
    
    for (var i = 0 ;i < lis.length; i++)  {
        lis[i].addEventListener('click',function() {
             // 派他思想
             for (var i = 0 ; i < lis.length; i++) {
                lis[i].style.border= '1px solid #e5e5e5' ;
            }
            this.style.border = '3px solid black';
        })
    }
})